﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Solution17
{

    IList<string> res;
    public IList<string> LetterCombinations(string digits)
    {
        res = new List<string>();


        if (digits.Length == 0) {
            return res;
        }


        Dictionary<char, string> dic = new Dictionary<char, string>();
        dic.Add('2', "abc");
        dic.Add('3', "def");
        
        dic.Add('4', "ghi");
        dic.Add('5', "jkl");
        dic.Add('6', "mno");
        dic.Add('7', "pqrs");
        dic.Add('8', "tuv");
        dic.Add('9', "wxyz");
        IList<string> strings = new List<string>();

        for (int i = 0; i < digits.Length; i++)
        {
            char curkey = digits[i];
            string curChar = dic[curkey];
            Console.WriteLine(curChar);

            strings.Add(curChar);
        }
        //IList<char> path = new List<char>();
        string path = null;

        DFS(strings, 0, path);

        return res;

    }

    private void DFS(IList<string> strings, int start, string path)
    {
        Console.WriteLine(path);
       
       
       

        //if (path!=null&&path.Length == strings.Count)
        //{
        //    Console.WriteLine(path.Length);
        //    string curpath = new string(path);
        //    res.Add(curpath);

        //    return;
        //}
        //简化代码

        if (start == strings.Count)
        {
      
            res.Add(path);

            return;
        }

        for (int i = 0; i < strings[start].Length; i++)
        {

            //path.Add(strings[start][i]);
            path += strings[start][i];
            DFS(strings, start + 1, path);

            //path.RemoveAt(path.Count-1);
            path= path.Substring(0, path.Length - 1);
            

        }
    }
}

class Program17
{
    static void Main17(string[] args)
    {
        Solution17 solution17 = new Solution17();
        //string digits = "23";
        string digits = "";
        IList<string>  res=solution17.LetterCombinations(digits);
        for (int i = 0; i < res.Count; i++) {


            Console.Write(res[i]+",");
        }
    }
}